package top.mccat.common.service.impl;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import top.mccat.common.core.domain.TreeSelect;
import top.mccat.common.core.domain.bk.BkSupplier;
import top.mccat.common.mapper.bk.BkSupplierMapper;
import top.mccat.common.service.IBkSupplierService;

import java.util.List;
import java.util.stream.Collectors;

/**
 * 供货商Service业务层处理
 * 
 * @author raven
 * @date 2022-11-06
 */
@Service
public class BkSupplierServiceImpl implements IBkSupplierService
{
    @Autowired
    private BkSupplierMapper bkSupplierMapper;

    /**
     * 查询供货商
     * 
     * @param id 供货商主键
     * @return 供货商
     */
    @Override
    public BkSupplier selectBkSupplierById(Integer id)
    {
        return bkSupplierMapper.selectBkSupplierById(id);
    }

    /**
     * 查询供货商列表
     * 
     * @param bkSupplier 供货商
     * @return 供货商
     */
    @Override
    public List<BkSupplier> selectBkSupplierList(BkSupplier bkSupplier)
    {
        return bkSupplierMapper.selectBkSupplierList(bkSupplier);
    }

    /**
     * 新增供货商
     * 
     * @param bkSupplier 供货商
     * @return 结果
     */
    @Override
    public int insertBkSupplier(BkSupplier bkSupplier)
    {
        return bkSupplierMapper.insertBkSupplier(bkSupplier);
    }

    /**
     * 修改供货商
     * 
     * @param bkSupplier 供货商
     * @return 结果
     */
    @Override
    public int updateBkSupplier(BkSupplier bkSupplier)
    {
        return bkSupplierMapper.updateBkSupplier(bkSupplier);
    }

    /**
     * 批量删除供货商
     * 
     * @param ids 需要删除的供货商主键
     * @return 结果
     */
    @Override
    public int deleteBkSupplierByIds(Integer[] ids)
    {
        return bkSupplierMapper.deleteBkSupplierByIds(ids);
    }

    /**
     * 删除供货商信息
     * 
     * @param id 供货商主键
     * @return 结果
     */
    @Override
    public int deleteBkSupplierById(Integer id)
    {
        return bkSupplierMapper.deleteBkSupplierById(id);
    }

    /**
     * @param suppliers 供货商列表
     * @return 结果
     */
    @Override
    public List<TreeSelect> buildSupplierTreeSelect(List<BkSupplier> suppliers) {
        return suppliers.stream().map(TreeSelect::new).collect(Collectors.toList());
    }
}
